package com.lb.shopguide.ui.fragment.guide.recommend;

import android.os.Bundle;

import com.lb.shopguide.R;
import com.lb.shopguide.base.BaseCommonFragment;
import com.lb.shopguide.constants.AppConstant;
import com.lb.shopguide.util.pic.GlideImageLoader;
import com.lb.shopguide.util.pic.GlideOrgImageLoader;
import com.youth.banner.Banner;
import com.youth.banner.BannerConfig;
import com.youth.banner.Transformer;
import com.youth.banner.view.BannerViewPager;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;

/**
 * Create by kangzhao on 2018/12/4
 */
public class FragmentGoodsImage extends BaseCommonFragment {
    @BindView(R.id.banner)
    Banner banner;

    private int curPos;
    private ArrayList<String> picList;

    public static FragmentGoodsImage newInstance(int position, List<String> list) {
        FragmentGoodsImage fragment = new FragmentGoodsImage();
        Bundle bundle = new Bundle();
        bundle.putInt(AppConstant.POSITION, position);
        bundle.putStringArrayList(AppConstant.PIC_URL_LIST, (ArrayList<String>) list);
        fragment.setArguments(bundle);
        return fragment;
    }

    @Override
    public int getLayoutId() {
        return R.layout.fragment_goods_image_gallery;
    }

    @Override
    public void initData() {
        Bundle bundle = getArguments();
        if (bundle.containsKey(AppConstant.POSITION)) {
            curPos = bundle.getInt(AppConstant.POSITION);
        }
        if (bundle.containsKey(AppConstant.PIC_URL_LIST)) {
            picList = bundle.getStringArrayList(AppConstant.PIC_URL_LIST);
        }
    }

    @Override
    public void initView() {
        banner.setImageLoader(new GlideOrgImageLoader());
        banner.setBannerStyle(BannerConfig.CIRCLE_INDICATOR);
        banner.setBannerAnimation(Transformer.DepthPage);
        //设置自动轮播，默认为true
        banner.isAutoPlay(false);
        banner.setImages(picList);
        banner.start();
        BannerViewPager viewPager = banner.getRootView().findViewById(R.id.bannerViewPager);
        viewPager.setCurrentItem(curPos + 1);
    }

    @Override
    public void finishRefresh() {

    }

    @Override
    public void sessionOutOfDate() {

    }

    @Override
    public void requestError(String error) {

    }

    @Override
    public String getPageTag() {
        return FragmentGoodsImage.class.getCanonicalName();
    }
}
